
# -*- coding:utf-8 -*-
import os, sys
# 获取osma输出
omreport = os.popen('omreport storage pdisk controller=0')
result = omreport.read()
result = result.strip()
# 将结果以空行分割,生成列表,列表的元素为单个磁盘的详情
disks = result.split('\n\n')
# 删除列表第一个元素
disks.pop(0)
# 处理第一个元素的非法格式【添加无用字符】
disks[0] = disks[0].replace(r'Embedded)', r'Embedded): xxxxx')

disk_sn = sys.argv[1]
disk_stat = sys.argv[2]
# 将单个磁盘的详情转换为字典####
for disk in disks:
    # 将磁盘详情分割为列表
    item = disk.split('\n')
    disk_dict = {}
    for ele in item:
        key, value = ele.split(': ')
        key = key.strip()
        key = key.replace(' ', '_')
        disk_dict[key] = value
    if disk_sn in disk_dict.values():
        print(disk_dict[disk_stat])
